package com.wchat.serviceimpl;

import java.io.UnsupportedEncodingException;

/**
 * Created by yangtianrui on 17/8/10.
 */
public class Jinzhi_4 {

    public static final void  Jinzhi(int a,int n)
    {
        int i = 0;
        int  chars[] = new int[1000];
        while(a>0)
        {
            chars[i++] = (a % n);
            a = a/n;
        }
        int k = i-1;
        for(int j = k;j>=0;j--)
        {
            System.out.println(chars[j]);
        }
    }

    public static String [] subString(String str,int chars) {
        int n = (str.length() + chars - 1) / chars;//  获取该字符传将分割为几段
        String[] newString = new String[100];//  新的字符串数组
        for (int i = 0; i < n; i++) {
            if (i < n - 1) {
                newString[i] = str.substring(i * chars, (i + 1) * chars);
            } else {
                newString[i] = str.substring(i * chars);//  截取剩下的
            }
        }
        return newString;
    }
    public static String [] split(String str,int chars)
    {
        int n = (str.length() +chars -1 ) / chars;
        String [] newString = new String[n];
        for(int i = 0 ; i< newString.length;i++)
        {
            if(i < n-1)
            {
                newString[i] = str.substring(i*chars,(i+1)*chars);
            }
            else
            {
                newString[i] = str.substring(i*chars);
            }
        }
        return  newString;
    }
    public static int  test() throws UnsupportedEncodingException {
       String str = "哈";
       byte [] b = str.getBytes("ISO-8859-1");
        return  b.length;
    }
    public static void main(String[] args) throws UnsupportedEncodingException {
        //Jinzhi(100,2);
        String newString = "我ABC汉DCF";
        //byte [] b = str.getBytes("utf8");
        //String newString  = new String(b,"utf8");
        String [] strs = split(newString,5);
        for (int i = 0; i <strs.length ; i++) {
            System.out.println(strs[i]);
        }
        String helle = "jelloisme";
        System.out.println(strs.length);
        System.out.println(helle.substring(0,3));//
        System.out.println(helle.substring(3,5));
        System.out.println(strs.length);

        //test();

        int length = test();
        System.out.println("length="+length);

//        String s1 = "你好";
//        try {
//            byte [] bytes =  s1.getBytes("GB2312");
//            String s2 = new String(bytes,"gb2312");
//            System.out.println(s2);
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
    }
}
